package com.sphd.restaurantsystem.base;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.chad.library.adapter.base.BaseQuickAdapter;
import com.sphd.restaurantsystem.R;
import com.sphd.restaurantsystem.info.LoginInfo;
import com.sphd.restaurantsystem.info.RestaurantInfo;

/**
 * Created by Hu on 2016/11/4.
 */

public abstract class BaseFragment extends Fragment {

    BaseActivity baseActivity;
    public Context context;
    boolean isViewCreated;
    private View footView;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        baseActivity = (BaseActivity) getActivity();
        context = getContext();
        View rootView = inflater.inflate(getLayout(), container, false);
        initViews(rootView);
        footView = View.inflate(context, R.layout.foot_view, null);
        isViewCreated = true;
        return rootView;
    }

    public abstract int getLayout();

    public abstract void initViews(View rootView);

    public void setRefresh(SwipeRefreshLayout myRefreshLayout) {
        baseActivity.setRefresh(myRefreshLayout);
    }

    public void setRecy(RecyclerView recy) {
//        recy.setHasFixedSize(true);
//        recy.setLayoutManager(new LinearLayoutManager(context));
        baseActivity.setRecy(recy);
//        recy.addItemDecoration(new DividerItemDecoration(this, DividerItemDecoration.VERTICAL_LIST));
    }
    public void showLoadingDialog() {
       baseActivity.showLoadingDialog();
    }

    public void dissLoadingDialog() {
       baseActivity.dissLoadingDialog();
    }
    public void addFootView(BaseQuickAdapter baseQuickAdapter) {
        baseQuickAdapter.removeAllFooterView();
        baseQuickAdapter.addFooterView(footView);
    }

    public boolean isReciverCanDo(LoginInfo loginInfo, RestaurantInfo restaurantInfo) {
        return baseActivity.isReciverCanDo(loginInfo, restaurantInfo);

    }

    public boolean isWaiterCanDo(LoginInfo loginInfo, RestaurantInfo restaurantInfo) {
        return baseActivity.isWaiterCanDo(loginInfo, restaurantInfo);
    }
    public void toast(Object o) {
       baseActivity.toast(o);

    }
}
